package com.example.computer_exam_training_sys.service.impl;
import com.example.computer_exam_training_sys.mapper.UserProgressMapper;
import com.example.computer_exam_training_sys.service.UserProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserProgressServiceImpl implements UserProgressService {

    @Autowired
    private UserProgressMapper progressMapper;

    @Override
    public void markPointCompleted(Integer userId, Integer pointId, Integer courseId) {
        if (progressMapper.exists(userId, pointId) > 0) {
            progressMapper.updateCompleted(userId, pointId);
        } else {
            progressMapper.insertCompleted(userId, pointId, courseId);
        }
    }

    @Override
    public int countCompletedPoints(Integer userId, Integer courseId) {
        return progressMapper.countCompletedPoints(userId, courseId);
    }
    @Override
    public List<Integer> getCompletedPointIds(Integer userId, Integer courseId) {
        return progressMapper.getCompletedPointIds(userId, courseId);
    }
    @Override
    public boolean isPointCompleted(Integer userId, Integer pointId) {
        return progressMapper.exists(userId, pointId) > 0;
    }


}